import {CreatePunch, GetTravelDetail, GetTravels, GetUserTravels, GetUserTravelsDetail} from "../../model/travels";
import {getSystemSize} from "../../utils/system"
let max = 35
let min = 12
let windowWidth = 0;
let windowHeight = 0;
Page({
    data: {
        locationList: [],
        current: 0,
        currentItem: {},
        punchList: [],
        arr: [],
        list: []
    },
    category: '',
    onLoad: async function (options) {
        this.category = options.category
        wx.setNavigationBarTitle({
            title: this.category
        })
        GetTravels({
            category: this.category
        }).then(res => {
            this.setData({
                locationList: res.data,
                currentItem: res.data[0]
            })
        })
    },
    onShow() {
        GetUserTravelsDetail().then(res => {
            this.setData({
                punchList: res
            })
        })
    },
    onSwiperChange(e) {
        this.setData({
            current: e.detail.current,
            currentItem: this.data.locationList[e.detail.current]
        })
    },
    onDetailTap() {
        wx.navigateTo({
            url: `/pages/travelDetail/index?id=${this.data.currentItem.id}&title=${this.data.currentItem.title}`
        })
        // wx.showLoading()
        // CreatePunch(this.data.currentItem.id, this.data.currentItem.category).then(res => {
        //     wx.hideLoading()
        //     if (res) {
        //         wx.navigateTo({
        //             url: `/pages/travelDetail/index?id=${this.data.currentItem.id}&title=${this.data.currentItem.title}`
        //         })
        //     }
        // }).catch(_ => {
        //     wx.hideLoading()
        // })
    },
    onDetail() {
        wx.navigateTo({
            url: `/pages/travelDetail/index?id=${this.data.currentItem.id}&title=${this.data.currentItem.title}`
        })
    },
    onRightTap() {
        this.setData({
            current: this.data.current + 1
        })
    },
    onLeftTap() {
        this.setData({
            current: this.data.current - 1
        })
    }
});
